package com.mmlc.meimei.lichengkongjian.shoppingbag;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidnetframe.BaseParentActivity;
import com.androidnetframe.httputil.BaseRequestFilterLayer;
import com.androidnetframe.responsejavabean.RequestError;
import com.androidnetframe.utils.LogUtils;
import com.androidnetframe.utils.UIUtils;
import com.mmlc.inter.InterFragment;
import com.mmlc.meimei.lichengkongjian.Adapter.WaitPayAdapter;
import com.mmlc.meimei.lichengkongjian.App;
import com.mmlc.meimei.lichengkongjian.MainActivity;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.meimei.lichengkongjian.been.WaitPayBean;
import com.mmlc.meimei.lichengkongjian.classify.FastGoodsDetailActivity;
import com.mmlc.meimei.lichengkongjian.classify.OrderFormActivity;
import com.mmlc.meimei.lichengkongjian.classify.ProductInfoActivity;
import com.mmlc.meimei.lichengkongjian.customview.MyDragLayout;
import com.mmlc.meimei.lichengkongjian.customview.slidemenu.SwipeMenuListView;
import com.mmlc.meimei.lichengkongjian.mine.LoginActivity;
import com.mmlc.network.filter.DeleteShoppingCartRequestFilter;
import com.mmlc.network.filter.RequestOrderCheckedAllFilter;
import com.mmlc.network.filter.ShoppingCartListRequestFilter;
import com.mmlc.network.filter.SubmitRequestFilter;
import com.mmlc.network.responsebean.DeleteShoppingCartResonseBean;
import com.mmlc.network.responsebean.ShoppingCarListResponseBean;
import com.mmlc.network.responsebean.SubmitResponseBean;
import com.mmlc.utils.PhoneUtils;
import com.mmlc.utils.SelectorUtils;
import com.mmlc.utils.ToastUtils;
import com.mmlc.utils.ViewUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;


public class ShoppingBagFragment extends InterFragment implements View.OnClickListener {

    @Override
    protected int initResourceID() {
        return R.layout.fragment_shoppingbag;
    }

    SwipeMenuListView lv_shopList;
    CheckBox cb_check;
    public TextView tv_edit;
    TextView tv_pay;
    TextView tv_totalMoney;
    RelativeLayout rl_bottom;
    ViewGroup rootView;
    RelativeLayout rl_bottomFiish;
    CheckBox cb_allCheckedFinish;
    TextView tv_btmDelete;
    ImageView iv_promote;
    ImageView iv_shop;
    ImageView iv_more;
    RelativeLayout noDadaUI;
    RelativeLayout shoppingCarContent;
    TextView tv_goSee;
    MyDragLayout dragLayout;
    SwipeRefreshLayout mRefreshLayout;
    LinearLayout ll_content;
    FrameLayout rl_noimei;
    TextView tv_imei;
    boolean isRefresh;
    @Override
    protected void initView() {
        lv_shopList = (SwipeMenuListView) view.findViewById(R.id.lv_shopList);
        cb_check = (CheckBox) view.findViewById(R.id.cb_check);
        tv_edit = (TextView) view.findViewById(R.id.tv_edit);
        tv_pay = (TextView) view.findViewById(R.id.tv_pay);
        tv_totalMoney = (TextView) view.findViewById(R.id.tv_totalMoney);
        rl_bottom = (RelativeLayout) view.findViewById(R.id.rl_bottom);
        rootView = (ViewGroup) view.findViewById(R.id.rootView);
        rl_bottomFiish = (RelativeLayout) view.findViewById(R.id.rl_bottomFiish);
        cb_allCheckedFinish = (CheckBox) view.findViewById(R.id.cb_allCheckedFinish);
        tv_btmDelete = (TextView) view.findViewById(R.id.tv_btmDelete);
        iv_promote = (ImageView) view.findViewById(R.id.iv_promote);
        iv_promote.setOnClickListener(this);
        iv_shop = (ImageView) view.findViewById(R.id.iv_shop);
        iv_shop.setOnClickListener(this);
        iv_more = (ImageView) view.findViewById(R.id.iv_more);
        ll_content = (LinearLayout) view.findViewById(R.id.ll_content);
        rl_noimei = (FrameLayout) view.findViewById(R.id.rl_noimei);
        tv_imei = (TextView) view.findViewById(R.id.tv_imei);
        iv_more.setOnClickListener(this);

        noDadaUI = (RelativeLayout) view.findViewById(R.id.noDadaUI);
        shoppingCarContent = (RelativeLayout) view.findViewById(R.id.shoppingCarContent);

        tv_goSee = (TextView) view.findViewById(R.id.tv_goSee);

        dragLayout = (MyDragLayout) view.findViewById(R.id.dragLayout);
        dragLayout.setDragHorizontal(true);
        dragLayout.setDragVertical(true);
        mRefreshLayout = ViewUtils.getView(view,R.id.refresh);
        mRefreshLayout.setColorSchemeColors(Color.RED);
//        mRefreshLayout.setProgressBackgroundColorSchemeColor(Color.RED);
        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if(!isRefresh) {
                    isRefresh = true;
                    requestNet();
                }
            }
        });
        processData();
    }

    @Override
    public void onResume() {
        super.onResume();
        if(haveShowEmtyView){
            closeEmtyView();
        }
        processData();

    }

    public boolean isEdit = true;

    private void processData() {
        cb_check.setClickable(false);
        cb_allCheckedFinish.setClickable(false);
//
//        if(App.user.getLoginState()){
////            dragLayout.setVisibility(View.VISIBLE);
////        }else{
////            dragLayout.setVisibility(View.GONE);
////        }

        tv_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (isEdit) {//编辑-完成

                    isEdit = false;
                    tv_edit.setText("完成");

                    rl_bottom.setVisibility(View.GONE);
                    rl_bottomFiish.setVisibility(View.VISIBLE);

                    if(App.user.getIsStore() ==1 || App.user.getIsTuiDan()== 1){
                        dragLayout.setVisibility(View.GONE);
                    }

                    recordBeforState();

                } else {
                    resetBeforState();
                  /*  int firstVisiblePosition = lv_shopList.getFirstVisiblePosition();
                    adapter.notifyDataSetChanged();
                    lv_shopList.setSelection(firstVisiblePosition);*/

                    isEdit = true;//编辑
                    tv_edit.setText("编辑");

                    rl_bottomFiish.setVisibility(View.GONE);

                    rl_bottom.setVisibility(View.VISIBLE);

                    if(App.user.getIsTuiDan() == 1 || App.user.getIsStore() == 1){
                        if(App.user.getLoginState()){
                            dragLayout.setVisibility(View.VISIBLE);
                        }
                    }

                }

            }
        });

        tv_pay.setOnClickListener(this);

        rl_bottom.setVisibility(View.GONE);

        //全选
        processSelectAll();

        rl_bottomFiish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                processRL_BottomFinish();
            }
        });

        //处理完成状态下的删除
        processFinishDelete();

        requestNet();
        
        
        //处理去逛逛
        processGoSee();
    }

    private void processGoSee() {
        tv_goSee.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), MainActivity.class);
                intent.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        });
    }
    private void processFinishDelete() {
        tv_btmDelete.setBackgroundDrawable(SelectorUtils.getSelector(SelectorUtils.Color_Red_Gray));
        tv_btmDelete.setOnClickListener(new View.OnClickListener() {

            public String[] getselecdAndPositionsId() {
                String[] values = new String[2];
                values[0] = "";
                values[1] = "";
                for (int i = 0; i < list.size(); i++) {
                    WaitPayBean.PayBean bean = list.get(i);
                    if (bean.isChecked) {
                        values[0] += bean.id + ",";
                        values[1] += i + ",";
                    }
                }
                if (!TextUtils.isEmpty(values[0])) {
                    values[0] = values[0].substring(0, values[0].lastIndexOf(','));
                    values[1] = values[1].substring(0, values[1].lastIndexOf(','));
                }

                return values;
            }

            @Override
            public void onClick(View v) {
                if (null == adapter){
                    return;
                }
                String[] strings = adapter.getSelecedIdAndPosition();
                if (TextUtils.isEmpty(strings[0])) {
                    ToastUtils.showToast("您还没有选择商品");
                    return;
                }
                deleteShop(strings[0], strings[1]);
            }
        });
    }

    public ArrayList<Integer> selectedPosition;

    private void recordBeforState() {
        selectedPosition = new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            WaitPayBean.PayBean payBean = list.get(i);
            if (payBean.isChecked) {
                selectedPosition.add(i);
            }
        }


    }

    private void resetBeforState() {
        for (int i = 0; i < list.size(); i++) {
            WaitPayBean.PayBean payBean = list.get(i);
            payBean.isChecked = false;
        }
        if(list.size()==0 || list ==null){
            return;
        }
        for (int i = 0; i < selectedPosition.size()-1; i++) {
            int pos = selectedPosition.get(i);
            WaitPayBean.PayBean payBean = list.get(pos);
            payBean.isChecked = true;
        }
        if(null == adapter){
            return;
        }
        adapter.notifyDataSetChanged();
    }


    List<Integer> currentSelect;

    private void retsetBeforeSelect() {
/*        currentSelect = new ArrayList<>();


        List<WaitPayBean.PayBean> payBeen = shoppingListFilter.responseBean.payBean;

        for(int i= 0;i<payBeen.size();i++){
            WaitPayBean.PayBean value = payBeen.get(i);
            if(value.isChecked){
                currentSelect.add(i);
            }
        }

        for (WaitPayBean.PayBean value : payBeen) {
            if(value.isChecked){

            }
            int tmpPostion = Integer.valueOf(value);
            payBeen.add(adapter.getItem(tmpPostion));
        }
        adapter.remove(payBeen);
        adapter.notifyDataSetChanged();*/
    }

    boolean finishSelectAll = false;

    private void processRL_BottomFinish() {
        if (finishSelectAll) {
            finishSelectAll = false;
            selectAllItem(false);
            cb_allCheckedFinish.setChecked(false);
        } else {
            finishSelectAll = true;
            selectAllItem(true);
            cb_allCheckedFinish.setChecked(true);
            adapter.selectedAll();

        }

    }

    boolean isSelectedAll = false;

    private void processSelectAll() {
        rl_bottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isSelectedAll) {
                    isSelectedAll = false;

                } else {
                    isSelectedAll = true;
                }

                allSelect(isSelectedAll);
            }
        });
    }

    private void allSelect(final boolean isChecked) {
        int type = -1;
        if (isChecked) {
            type = 1;
        } else {
            type = 0;
        }
        RequestOrderCheckedAllFilter filter = new RequestOrderCheckedAllFilter(context);
        filter.offerErrorParams(rootView);
        filter.isTransparence = true;
        filter.requestBean.type = type;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<String>() {
            @Override
            public void onSuccess(String result) {
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject(result);
                    JSONObject data = jsonObject.getJSONObject("data");
                    String total_price = data.optString("total_price");
                    showPayState(total_price);

                    shopOriginal = data.optString("total_price_market");

                    cb_check.setChecked(isChecked);

                    tv_totalMoney.setText("合计:¥" + total_price);

                    selectAllItem(isChecked);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
            }
        });
    }

    private void selectAllItem(boolean isChecked) {

        for (WaitPayBean.PayBean bean : list) {
            if (isChecked) {
                bean.isChecked = true;
            } else {
                bean.isChecked = false;
            }
        }
        /*adapter.notifyDataSetChanged();*/
        int firstVisiblePosition = lv_shopList.getFirstVisiblePosition();
        if(null == shoppingListFilter.responseBean){
            return;
        }
        adapter = new WaitPayAdapter(shoppingListFilter,ShoppingBagFragment.this, context, lv_shopList, shoppingListFilter.responseBean, rootView);
        lv_shopList.setAdapter(adapter);
        adapter.setUpDatePrice(new WaitPayAdapter.UpDatePrice() {
            @Override
            public void update(String totalPrice) {
                tv_totalMoney.setText("合计:¥" + totalPrice);
                showPayState(totalPrice);
            }
        });
        lv_shopList.setSelection(firstVisiblePosition);

    }

    /**
     * 是否有选中的选项
     */
    private boolean haveSelected() {
        boolean returnValue = false;
        for (WaitPayBean.PayBean bean : list) {
            if (bean.isChecked) {
                returnValue = true;
                break;
            }
        }
        return returnValue;
    }

    ShoppingCartListRequestFilter shoppingListFilter;

    private void requestNet() {
        shoppingListFilter = new ShoppingCartListRequestFilter(context);
        shoppingListFilter.offerErrorParams(rootView);
        String imei = PhoneUtils.getIMEI(getActivity());
        if(null ==imei || TextUtils.isEmpty(imei)){
            ll_content.setVisibility(View.GONE);
            rl_noimei.setVisibility(View.VISIBLE);
            tv_imei.setVisibility(View.VISIBLE);
            return;
        }
        shoppingListFilter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<ShoppingCarListResponseBean>() {
            @Override
            public void onSuccess(ShoppingCarListResponseBean result) {

                ll_content.setVisibility(View.VISIBLE);
                rl_noimei.setVisibility(View.GONE);
                tv_imei.setVisibility(View.GONE);
                shopOriginal = result.getData().getTotal_price_market();
                mRefreshLayout.setRefreshing(false);
                isRefresh = false;
                //处理订单列表
                processShopList(shoppingListFilter);

                //根据type确定"推-店"是否显示
                if(App.user.getLoginState()){

                    showPush(App.user.getIsStore(),App.user.getIsTuiDan());
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
                closeEmtyView();
                ll_content.setVisibility(View.GONE);
                rl_noimei.setVisibility(View.VISIBLE);
                tv_imei.setVisibility(View.VISIBLE);
                mRefreshLayout.setRefreshing(false);
            }
        });
    }
    private void showPush(int is_store,int is_tuidan) {
        if(is_store==1&&is_tuidan==1) {//内部员工 展示推单和店
            iv_promote.setVisibility(View.GONE);
            iv_shop.setVisibility(View.GONE);
            dragLayout.setVisibility(View.VISIBLE);
            iv_more.setVisibility(View.VISIBLE);
            return;
        }
        if(is_tuidan ==1 && is_store == 0) {
            iv_promote.setVisibility(View.GONE);
            iv_shop.setVisibility(View.GONE);
            dragLayout.setVisibility(View.VISIBLE);
            iv_more.setVisibility(View.VISIBLE);
            return;
        }
        if(is_tuidan ==0 && is_store ==1) {
            iv_promote.setVisibility(View.GONE);
            iv_shop.setVisibility(View.GONE);
            dragLayout.setVisibility(View.VISIBLE);
            iv_more.setVisibility(View.VISIBLE);
            return;
        }
        if(is_tuidan ==0 && is_store ==0){
            dragLayout.setVisibility(View.GONE);
            iv_more.setVisibility(View.GONE);
        return;
        }
    }
    WaitPayAdapter adapter;
    List<WaitPayBean.PayBean> list = new ArrayList<>();

    private void processShopList(ShoppingCartListRequestFilter filter) {
        ///list = ShopOrderUtils.getWaitPay();
        list = filter.responseBean.payBean;
        if (list.size() > 0) {
            closeEmtyView();
            rl_bottomFiish.setVisibility(View.GONE);
            rl_bottom.setVisibility(View.VISIBLE);
            isEdit = true;
            tv_edit.setText("编辑");
            tv_totalMoney.setText("合计:¥" + filter.responseBean.totalPrice);

            //看是否有选中的商品，如果没有，应该让结算按钮的背景颜色为灰色
            showPayState(filter.responseBean.totalPrice);
            adapter = new WaitPayAdapter(shoppingListFilter,ShoppingBagFragment.this, context, lv_shopList, filter.responseBean, rootView);
            lv_shopList.setAdapter(adapter);
            addAdapterItem(lv_shopList, filter.responseBean.payBean);
            adapter.setUpDatePrice(new WaitPayAdapter.UpDatePrice() {
                @Override
                public void update(String totalPrice) {
                    tv_totalMoney.setText("合计:¥" + totalPrice);
                    showPayState(totalPrice);
                }
            });

        } else {
            showEmtyView();
        }

    }


    boolean haveShowEmtyView =  false;
    private void showEmtyView() {
        haveShowEmtyView = true;
        noDadaUI.setVisibility(View.VISIBLE);
        dragLayout.setVisibility(View.GONE);
        shoppingCarContent.setVisibility(View.GONE);
        rl_bottomFiish.setVisibility(View.GONE);
    }
    private void closeEmtyView(){
        haveShowEmtyView = false;
        noDadaUI.setVisibility(View.GONE);
        if(App.user.getLoginState()){
            dragLayout.setVisibility(View.VISIBLE);
        }else{

            dragLayout.setVisibility(View.GONE);
        }

        shoppingCarContent.setVisibility(View.VISIBLE);
        rl_bottomFiish.setVisibility(View.VISIBLE);
    }


    private void hideUI() {
        rl_bottom.setVisibility(View.GONE);
        rl_bottomFiish.setVisibility(View.GONE);
        tv_edit.setText("编辑");
        isEdit = true;
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()) {
            case R.id.tv_pay:
                /*try {
                    ReflectToBeanUtils.reflectJsonToBean(ShopOrderPayMethodRequestFilter.ShopOrderBean.class,null,0);
                } catch (Exception e) {
                    e.printStackTrace();
                }*/
                if(null != App.user && !App.user.getLoginState()){
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.putExtra("type","count");
                    startActivity(intent);
                    return;
                }
                UIUtils.simpleStartActivity(OrderFormActivity.class);
                break;
            case R.id.iv_promote://处理推单
                processPromote();
                break;
            case R.id.iv_shop://处理店铺下单
                openShopOrder();
                break;
            case R.id.iv_delete:
            case R.id.tv_cancel:
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
                break;
            case R.id.tv_confirm:
                processPromoteConfirm();
                break;
            case R.id.iv_more://展示推单或店界面
                showMore();
                break;
        }

    }

    public boolean clickedMore;
    private void showMore() {
        if(clickedMore){//关闭
            clickedMore = false;
            if(App.user.getUserType() == 1){
                iv_promote.setVisibility(View.GONE);
                iv_shop.setVisibility(View.GONE);
            }else if(App.user.getUserType() == 3){
                iv_promote.setVisibility(View.GONE);
            }
        }else{//展开
            clickedMore = true;
            if(App.user.getUserType() == 1){
                iv_promote.setVisibility(View.VISIBLE);
                iv_shop.setVisibility(View.VISIBLE);
            }else if(App.user.getUserType() == 3){
                iv_promote.setVisibility(View.VISIBLE);
            }
        }
    }


    public String shopOriginal="";
    private void openShopOrder() {
        if (!haveSelected()) {//是否有选中商品
            ToastUtils.showToast("您还没有选择商品哦");
            return;
        }

        Intent intent = new Intent(getActivity(), PayTypeActivity.class);
        intent.putExtra("market_price",shopOriginal);
        startActivity(intent);
    }


    private void processPromoteConfirm() {
        String s = et_inputPhone.getText().toString();
        if (TextUtils.isEmpty(s)) {
            ToastUtils.showToast("请输入内容");
            return;
        }
        recommendOrder(s);
        //发送一个网络请求
    }

    Dialog dialog;
    EditText et_inputPhone;
    TextView tv_cancel;
    TextView tv_confirm;
    FrameLayout iv_delete;

    //推单跳转
    private void processPromote() {
        if (!haveSelected()) {//是否有选中商品
            ToastUtils.showToast("您还没有选择商品哦");
            return;
        }

        Intent intent = new Intent(getActivity(),PromoteActivity.class);
        startActivity(intent);

//        View view = null;
//        if (dialog == null) {
//            view = View.inflate(getActivity(), R.layout.dialog_promote, null);
//            et_inputPhone = (EditText) view.findViewById(R.id.et_inputPhone);
//            tv_cancel = (TextView) view.findViewById(R.id.tv_cancel);
//            tv_cancel.setOnClickListener(this);
//            tv_confirm = (TextView) view.findViewById(R.id.tv_confirm);
//            tv_confirm.setOnClickListener(this);
//            iv_delete = (FrameLayout) view.findViewById(R.id.iv_delete);
//            iv_delete.setOnClickListener(this);
//
//            dialog = new Dialog(getActivity(), R.style.centerDialog);
//            dialog.setContentView(view);
//        }
//        dialog.show();



    }

    public void addAdapterItem(final SwipeMenuListView lv_shopList, final List<WaitPayBean.PayBean> payBean) {

//        SwipeMenuCreator creator = new SwipeMenuCreator() {
//
//            @Override
//            public void create(SwipeMenu menu) {
//
//                // create "delete" item
//                SwipeMenuItem deleteItem = new SwipeMenuItem(
//                        context);
//                deleteItem.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
//
//                deleteItem.setBackground(R.color.common_background);
//
//                deleteItem.setView(R.layout.adapter_shopping_delete_item);
//                menu.addMenuItem(deleteItem);
//            }
//        };
        // set creator
//        lv_shopList.setMenuCreator(creator);

//        lv_shopList.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
//            @Override
//            public void onMenuItemClick(final int position, SwipeMenu menu, int index) {
//                switch (index) {
//                    case 0:
//                        String id = payBean.get(position).id;//购物车的id
//
//                        deleteShop(id, position + "");
//                        break;
//                }
//            }
//        });
        lv_shopList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (isEdit) {
                    if(list.get(position).type == 0) {
                        Intent intent = new Intent(context, ProductInfoActivity.class);
                        intent.putExtra("goods_id", list.get(position).goodsId);
                        startActivity(intent);
                    }else if(list.get(position).type == 1){
                        LogUtils.e("type",1);
                        Intent intent = new Intent(context, FastGoodsDetailActivity.class);
                        intent.putExtra("id", list.get(position).goodsId);
                        startActivity(intent);
                    }
                }
            }
        });

    }

    /**
     * shopId:如果有多个Id,每个Id都以","隔开
     * position:如果有多个位置，每个位置以"，"隔开
     */
    private void deleteShop(String shopId, final String position) {
        final DeleteShoppingCartRequestFilter filter = new DeleteShoppingCartRequestFilter(context);
        filter.offerErrorParams(rootView);
        filter.isTransparence = true;
        filter.requestBean.cid = shopId;//相当于是订单Id了
        filter.requestBean.imei = PhoneUtils.getIMEI(context);
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<DeleteShoppingCartResonseBean>() {

            @Override
            public void onSuccess(DeleteShoppingCartResonseBean result) {
                ToastUtils.showToast("删除成功");
                shopOriginal = result.getData().getTotal_price_market();
                removeItem(position);

                setTotalMoney(filter.totalPrice);

                if (adapter.haveData()) {

                } else {
                    showEmtyView();
                }
                adapter.resetSelecedIdAndPosition();
                showPayState(filter.totalPrice);
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
                ToastUtils.showToast(serverError.mess);
            }

            public void removeItem(String positions) {
                String[] position = positions.split(",");

                ArrayList<WaitPayBean.PayBean> payBeen = new ArrayList<>();

                for (String value : position) {
                    int tmpPostion = Integer.valueOf(value);
                    payBeen.add(adapter.getItem(tmpPostion));
                }
                adapter.remove(payBeen);
                adapter.notifyDataSetChanged();
            }
        });
    }

    //展示结算状态
    public void showPayState(String price) {
        float value = Float.valueOf(price);
        if (value > 0) {
            tv_pay.setClickable(true);
            tv_pay.setBackgroundColor(getResources().getColor(R.color.text_01));

        } else {
            tv_pay.setClickable(false);
            tv_pay.setBackgroundColor(getResources().getColor(R.color.color_gray_B7B7B7));
        }
    }

    public void setTotalMoney(String price) {
        tv_totalMoney.setText("合计:¥" + price);
    }

    private void recommendOrder(String phone) {
        SubmitRequestFilter filter=new SubmitRequestFilter((BaseParentActivity) getActivity());
        filter.requestBean.type="2";
        filter.requestBean.phone=phone;
        filter.sendRequest(new BaseRequestFilterLayer.AccessResultFromFilter<SubmitResponseBean>() {
            @Override
            public void onSuccess(SubmitResponseBean result) {
                ToastUtils.showToast("订单提交成功");
                requestNet();
                if(dialog != null && dialog.isShowing()){
                    dialog.dismiss();
                }
            }

            @Override
            public void onFailed(View errorLayout, RequestError serverError, int failedType) {
               ToastUtils.showToast(serverError.mess);
                //以下的通知方式，在红米手机上无法显示，因此不要用下面这个类
                //CustomToast.makeText(getActivity(),serverError.mess,3000).show();
            }
        });
    }

}
